require("@nomicfoundation/hardhat-toolbox");
require("@nomicfoundation/hardhat-verify");
require("@nomicfoundation/hardhat-ethers");
require("solidity-coverage");
require("hardhat-gas-reporter");
require("hardhat-contract-sizer");
require("hardhat-deploy");
require("hardhat-deploy-ethers"); // 这个插件是为了使用 ethers.js 的 deploy 功能，如 ethers.getContract()
require("dotenv").config();

const ETHER_MAINNET_RPC_URL = 
    process.env.ETHER_MAINNET_RPC_URL || "https://mainnet.infura.io/v3/<YOUR-API-KEY>"
const SEPOLIA_RPC_URL =
    process.env.SEPOLIA_RPC_URL || "https://sepolia.infura.io/v3/<YOUR-API-KEY>"
const POLYGON_MAINNET_RPC_URL =
    process.env.POLYGON_MAINNET_RPC_URL || "https://polygon-mainnet.infura.io/v3/<YOUR-API-KEY>"
const PRIVATE_KEY = process.env.PRIVATE_KEY || undefined
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "Your coinmarketcap API key"
// optional
const MNEMONIC = process.env.MNEMONIC || "your mnemonic"
// Your API key for Etherscan, obtain one at https://etherscan.io/
const ETHERSCAN_API_KEY =
  process.env.ETHERSCAN_API_KEY || "Your etherscan API key";
const REPORT_GAS = process.env.REPORT_GAS || false;

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.28",
  defaultNetwork: "hardhat",
  networks: {
    hardhat: {
        // // If you want to do some forking, uncomment this
        // forking: {
        //   url: ETHER_MAINNET_RPC_URL
        // }
        chainId: 31337,
        blockConfirmations: 1,
    },
    localhost: {
        chainId: 31337,
        blockConfirmations: 1,
    },
    sepolia: {
        url: SEPOLIA_RPC_URL,
        accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
        //   accounts: {
        //     mnemonic: MNEMONIC,
        //   },
        saveDeployments: true,
        chainId: 11155111,
        blockConfirmations: 6,
    },
    mainnet: {
        url: ETHER_MAINNET_RPC_URL,
        accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
        //   accounts: {
        //     mnemonic: MNEMONIC,
        //   },
        saveDeployments: true,
        chainId: 1,
        blockConfirmations: 6,
    },
    polygon: {
        url: POLYGON_MAINNET_RPC_URL,
        accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
        saveDeployments: true,
        chainId: 137,
        blockConfirmations: 6,
    },
  },
   etherscan: {
    apiKey: {
      sepolia: ETHERSCAN_API_KEY,
    },
  },
  contractSizer: {
    runOnCompile: true,
    disambiguatePaths: false, // 避免合约路径冲突,在输出合约大小时,显示完整路径而不是只显示合约名
    only: ["Raffle"],
  },
  namedAccounts: {
    deployer: {
        default: 0, // here this will by default take the first account as deployer
        1: 0, // 指定了在链 ID 为 1(即以太坊主网)时使用的账户索引
    },
    player1: {
        default: 1,
    },
    player2: {
      default: 2,
    },
    player3: {
      default: 3,
    },
  },
  gasReporter: {
    enabled: REPORT_GAS,
    currency: "USD",
    outputFile: "gas-report.txt",
    // Colors: true,
    // coinmarketcap: COINMARKETCAP_API_KEY,
    // token: 'MATIC', // 代币网络
  },
  mocha: {
    timeout: 200000, // 200 seconds max for running tests
  },
};
